package com.tangsm.redis.script.controller;

import com.tangsm.redis.script.core.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * RedisScript测试服务接口
 * @author tangsm
 */
@RestController
@RequestMapping("/api")
public class RedisScriptController {
    @Autowired
    private RedisService redisService;

    @PostMapping("/set")
    public String set(@RequestBody String param) {
        Boolean aBoolean = redisService.set("DEV:API:SET", param, 1000L);
        return Boolean.TRUE.equals(aBoolean) ? "成功" : "失败";
    }

    @GetMapping("/get")
    public String get() {
        Object o = redisService.get("DEV:API:SET");
        return Objects.isNull(o) ? "获取失败" : o.toString();
    }
}
